package cn.china.springboot.controller;

import cn.china.springboot.serviceimpl.UserServiceImpl;
import entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@CrossOrigin
@RestController
@RequestMapping
public class UserController {
    @Autowired
    UserServiceImpl usi;

    /**
     * 登录
     * @param username
     * @param password
     * @param response
     * @return
     */
    @RequestMapping(value = "/login", produces = "application/json;charset=UTF-8")
    public String login(@RequestParam String username, @RequestParam String password, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        return usi.Login(username, password);
    }

    /**
     * 注册
     * @param username
     * @param password
     * @param phone
     * @param response
     * @return
     */
    @RequestMapping(value = "/register", produces = "application/json;charset:UTF-8")
    public String register(@RequestParam String username, @RequestParam String password, @RequestParam String phone, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        return usi.register(username, password, phone);
    }
}
